

const { createProject, updateById, updateStatusById, queryAll, queryMyAll } = require('../service/project.service')

class ProjectController {
    async create(ctx) {
        const project = ctx.request.body
        project.director = ctx.state.emp.id
        project.status = 0
        const res = await createProject(project)
        ctx.body = {
            code: '200',
            message: '申请发起，待审核',
            data: res
        }
    }

    async update(ctx) {

        const project = ctx.request.body
        project.id = ctx.request.params.id
        console.log(project);
        const res = await updateById(project)
        ctx.body = {
            code: '200',
            message: '修改成功'
        }
    }

    async updateStatus(ctx) {
        const id = ctx.request.params.id
        const status = ctx.request.params.status
        const res = await updateStatusById(id, status)
        ctx.body = {
            code: '200',
            message: '操作成功'
        }
    }

    async query(ctx) {
        const { pageNum = 1, pageSize = 5 } = ctx.request.query
        const status=ctx.request.params.status
        const res = await queryAll(pageNum, pageSize, {status})
        ctx.body = {
            code: '200',
            message: '项目列表获取成功',
            data: res
        }
    }
    async queryMy(ctx) {
        const empId = ctx.state.emp.id
        const res = await queryMyAll({empId})

        ctx.body = {
            code: '200',
            message: '项目列表获取成功',
            data: res
        }
    }

    async statusQueryMy(ctx){
        const empId = ctx.state.emp.id
        const status=ctx.request.params.status
        
        const res = await queryMyAll({empId,status})

        ctx.body = {
            code: '200',
            message: '项目列表获取成功',
            data: res
        }
    }
}

module.exports = new ProjectController()